import {Component, ElementRef, Renderer2, AfterViewInit, OnDestroy} from '@angular/core';
import {InfiniteScrollService} from './infinite-scroll.service';

@Component({
  selector: 'kylin-infinite-scroll',
  templateUrl: './infinite-scroll.component.html',
  styleUrls: ['./infinite-scroll.component.less']
})
export class InfiniteScrollComponent implements AfterViewInit, OnDestroy {
  testData = [];

  constructor(private elementRef: ElementRef, private renderer: Renderer2, private infiniteScrollService: InfiniteScrollService) {
    for (let i = 0; i < 50; i++) {
      this.testData.push({});
    }
  }


  onScroll() {
    console.log('onScroll');
    this.infiniteScrollService.fetchScrollData().then(res => {
      setTimeout(() => {
        this.testData.push(...res.data);
      }, 1000);
    });
  }

  ngAfterViewInit() {

  }

  ngOnDestroy() {

  }
}
